package cn.rkylin.oms.salespromotion.rules.dao.impl.mybatis;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.salespromotion.rules.dao.ISalesPromotionConstrainGoodsDAO;
import cn.rkylin.oms.salespromotion.rules.domain.SalesPromotionConstrainGoods;
/**
 * 促销相关限制商品的数据访问层
 * @author zhanghao
 * @version 1.0
 * @created 21-8月-2017 17:59:30
 */
@Repository(value = "constrainGoodsDAO")
public class SalesPromotionConstrainGoodsDAOImpl implements ISalesPromotionConstrainGoodsDAO{

    private static final String STMT_DELETE_BY_RULE_ID = "updateConstrainGoodsByRelRuleSelective";
    private static final String STMT_SELECT_BY_RULE_ID = "selectConstrainGoodsByRuleId";
    private static final String STMT_INSERT_BY_RULE_ID = "insertConstrainGoodsSelective";
    
    @Autowired
    protected IDataBaseFactory dao;
    
    public SalesPromotionConstrainGoodsDAOImpl() {
        
    }

    @Override
    public int deleteByRuleId(String ruleId) throws Exception {
        SalesPromotionConstrainGoods constrainGoods = new SalesPromotionConstrainGoods();
        constrainGoods.setRelRuleId(ruleId);
        constrainGoods.setDeleted("y");
        constrainGoods.setUpdateTime(new Date());
        return dao.delete(STMT_DELETE_BY_RULE_ID, constrainGoods);
    }

    @Override
    public int insert(SalesPromotionConstrainGoods record) throws Exception {
        return dao.insert(STMT_INSERT_BY_RULE_ID, record);
    }

    @Override
    public List<SalesPromotionConstrainGoods> selectByRuleId(String ruleId) throws Exception {
        SalesPromotionConstrainGoods constrainGoods = new SalesPromotionConstrainGoods();
        constrainGoods.setRelRuleId(ruleId);
        constrainGoods.setUpdateTime(new Date());
        constrainGoods.setDeleted("y");
        return dao.find(STMT_SELECT_BY_RULE_ID, constrainGoods);
    }

}
